/*
   Find merge point of two linked lists
   Node is defined as
   struct Node
   {
       int data;
       Node* next;
   }
*/
int length(Node *head) {
    int l = 0;
    while(head != NULL) {
        l++;
        head = head->next;
    }
    return l;
}
Node *ascent(Node *head, int n) {
    for(int i = 0; i < n; i++)
        head = head->next;
    return head;
}
int FindMergeNode(Node *headA, Node *headB)
{
    // Complete this function
    // Do not write the main method.
    int lenA = length(headA), lenB = length(headB);
    if(lenA > lenB)
        headA = ascent(headA, lenA - lenB);
    else
        headB = ascent(headB, lenB - lenA);
    while(headA != NULL && headB != NULL && headA != headB) {
        headA = headA->next;
        headB = headB->next;
    }
    return headA->data;
}